﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using OpenSISMenuBusinessLogic;
using OpenSISDataConnection;

namespace OpenSISMenuDataLayer
{
    /// <summary>
    /// Summary description for MainMenuDL
    /// </summary>
    public class MainMenuDL
    {
        public System.Data.DataTable ViewAllMenuItem()
        {
            DataTable dt = null;

            try
            {
                dt = DataConnection.ConnectionPath.Getdata("Select Main_menu_ID,Main_Menu_Header,url from Main_Menu order by Main_Menu_ID").Tables[0];
                return dt;
            }
            catch
            {
                return null;
            }
        }

        public System.Data.DataTable ViewAllSubMenuItem(MainMenuBL Main_menu)
        {
            DataTable dt = null;

            try
            {
                //dt = DataConnection.ConnectionPath.Getdata("Select Main_SubMenu_ID,Main_Menu_ID,Main_SubMenu_Header,Url,Visible from Main_SubMenu where Main_menu_ID=" + Main_menu.MMenuId + " Order by Main_SubMenu_ID").Tables[0];

                dt = DataConnection.ConnectionPath.Getdata("Select Main_SubMenu_ID,Main_Menu_ID,Main_SubMenu_Header,Url,Visible from Main_SubMenu where Main_menu_ID=(Select Main_menu_ID from Main_Menu where Main_Menu_Header='" + Main_menu.MMenuHeader + "') Order by Main_SubMenu_ID").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }





        public System.Data.DataTable ViewAllSubMenuChildItem(MainMenuBL Main_menu)
        {
            DataTable dt = null;

            try
            {
                dt = DataConnection.ConnectionPath.Getdata("Select * from Main_SubMenu_Child where Main_SubMenu_ID=(Select MS.Main_SubMenu_ID from Main_SubMenu MS,Main_Menu MM where MM.Main_Menu_ID = MS.Main_menu_ID and MS.Main_SubMenu_Header='" + Main_menu.MSMenuHeader + "' and MM.Main_Menu_Header='" + Main_menu.MMenuHeader + "') Order by Main_SubMenu_Child_Id").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }

        public System.Data.DataTable ViewSubMenuItemUrl(MainMenuBL Sub_menu)
        {
            DataTable dt = null;

            try
            {

                dt = DataConnection.ConnectionPath.Getdata("Select Url from Main_SubMenu where visible='V' and Main_SubMenu_Header= '" + Sub_menu.MMenuHeader + "'").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }



        public System.Data.DataTable ViewSubMenuChildItemUrl(MainMenuBL Sub_menu)
        {
            DataTable dt = null;

            try
            {

                //dt = DataConnection.ConnectionPath.Getdata("Select Url from Main_SubMenu_child where Main_SubMenu_Child_Header= '" + Sub_menu.MSChildMenuHeader + "'").Tables[0];

                dt = DataConnection.ConnectionPath.Getdata("select Main_SubMenu_child.Url,main_subMenu_Header from Main_SubMenu,Main_SubMenu_child where Main_SubMenu.main_submenu_id=Main_SubMenu_child.main_submenu_id and Main_SubMenu_Child.visible='V' and Main_SubMenu_Child_Header= '" + Sub_menu.MSChildMenuHeader + "'").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }


        public System.Data.DataTable ViewMainMenuItemUrl(MainMenuBL Main_menu)
        {
            DataTable dt = null;

            try
            {

                dt = DataConnection.ConnectionPath.Getdata("Select Url from Main_Menu where Main_Menu_Header= '" + Main_menu.MMenuHeader + "'").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }




        public System.Data.DataTable ViewAllMenuItemMultilang(MainMenuBL mmbl)
        {
            DataTable dt = null;

            try
            {
                dt = DataConnection.ConnectionPath.Getdata("Select Menu_id,Menu_Header,URL from Menu_Multilingual where Menu_Type='" + mmbl.MenuType + "' and Language_Type='" + mmbl.LanguageType + "'").Tables[0];
                return dt;
            }
            catch
            {
                return null;
            }
        }


        public System.Data.DataTable ViewMainMenuItemUrlMultilang(MainMenuBL Main_menu)
        {
            DataTable dt = null;

            try
            {

                dt = DataConnection.ConnectionPath.Getdata("Select URL from Menu_Multilingual where Menu_Header=N'" + Main_menu.MMenuHeader.Replace("'", "''") + "'").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }


        public System.Data.DataTable ViewAllSubMenuItemMultilingual(MainMenuBL Main_menu)
        {
            DataTable dt = null;

            try
            {


                dt = DataConnection.ConnectionPath.Getdata("Select * from SubMenu_Multilingual where Main_menu_id=(Select Menu_id from Menu_Multilingual where Menu_Header=N'" + Main_menu.MMenuHeader.Replace("'", "''") + "')").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }

        public System.Data.DataTable ViewSubMenuItemUrlMulilingual(MainMenuBL Sub_menu)
        {
            DataTable dt = null;

            try
            {

                dt = DataConnection.ConnectionPath.Getdata("Select URL from SubMenu_Multilingual where visible='V' and SubMenu_Header=N'" + Sub_menu.MMenuHeader.Replace("'", "''") + "'").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }

        public System.Data.DataTable ViewAllSubMenuChildItemMultilingual(MainMenuBL Main_menu)
        {
            DataTable dt = null;

            try
            {
                dt = DataConnection.ConnectionPath.Getdata("Select * from SubMenu_Child_Multilingual where SubMenu_Id=(Select MS.SubMenu_id from SubMenu_Multilingual MS,Menu_Multilingual MM where MM.Menu_id = MS.Main_menu_id and MS.SubMenu_Header=N'" + Main_menu.MSMenuHeader.Replace("'", "''") + "' and MM.Menu_Header=N'" + Main_menu.MMenuHeader.Replace("'", "''") + "') Order by SubMenu_Child_Id").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }

        public System.Data.DataTable ViewSubMenuChildItemUrlMultilingual(MainMenuBL Sub_menu)
        {
            DataTable dt = null;

            try
            {

                //dt = DataConnection.ConnectionPath.Getdata("Select URL from SubMenu_Child_Multilingual where SubMenu_Child_Header=N'" + Sub_menu.MSChildMenuHeader.Replace("'", "''") + "'").Tables[0];

                dt = DataConnection.ConnectionPath.Getdata("Select SubMenu_Child_Multilingual.URL,subMenu_Header from SubMenu_Multilingual,SubMenu_Child_Multilingual where SubMenu_Child_Multilingual.SubMenu_id=SubMenu_Multilingual.SubMenu_id and  SubMenu_Child_Multilingual.visible='V' and SubMenu_Child_Header=N'" + Sub_menu.MSChildMenuHeader.Replace("'", "''") + "'").Tables[0];

                return dt;
            }
            catch
            {
                return null;
            }
        }


    }
}
